<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/20 0020
 * Time: 22:56
 */

namespace app\admin\controller;
use app\admin\model\Admin as AdminModel;
use think\Controller;
use think\Db;
class AdminManage extends Controller
{
    //中间件登录限制
    protected $middleware = [
        'AdminCheck'
    ];
    //管理员列表
    public function admin_list(){
        $admin=Db::table('admin')->select();
        $this->assign('admin',$admin);
        return $this->fetch();
    }
    //后台管理禁用
    public function admin_down(){
        $id=input('post.id');
        $admin=Db::table('admin')
            ->where('id',$id)
            ->update([
                'statu' => 0
            ]);
        if ($admin){
            $msg=[
                'statu'=>200,
                'msg'  =>'禁用成功'
            ];
        }else{
            $msg=[
                'statu'=>200,
                'msg'  =>'禁用成功'
            ];
        }
        return $msg;
    }
    //后台管理员启用
    public function admin_up(){
        $id=input('post.id');
        $admin=Db::table('admin')
            ->where('id',$id)
            ->update([
                'statu' => 1
            ]);
        if ($admin){
            $msg=[
                'statu'=>200,
                'msg'  =>'启用成功'
            ];
        }else{
            $msg=[
                'statu'=>200,
                'msg'  =>'启用成功'
            ];
        }
        return $msg;
    }
    //后台管理员添加
    public function admin_add(){
        if ($this->request->isAjax()){
            $data=input('post.');
            $admin=new AdminModel();
            $admin=$admin->admin_add($data);
            if ($admin){
                $msg=[
                    'statu'=>200,
                    'msg'  =>'管理员添加成功'
                ];
            }else{
                $msg=[
                    'statu'=>400,
                    'msg'  =>'管理员添加失败'
                ];
            }
            return $msg;
        }
        return $this->fetch();
    }

}